﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AForge;
using AForge.Genetic;

namespace dto
{
    public class AckleyProblemBinary : OptimizationFunction1D 
        {
        public AckleyProblemBinary() : 
            base (new Range(-20, 30) ) { } 

        public override double OptimizationFunction(double x)
        {
            // TODO: n(5,10,...,40) dynamically
            // divide sum and product function of the whole function f(x) = g(x) - h(x)
            double functionValueGx = 0.0, functionValueHx = 0.0, chromosomeValue = 0.0;
            for (int i = 1; i < 5; ++i)
            {
                chromosomeValue = x;
                functionValueGx += Math.Pow(chromosomeValue, 2);
                functionValueHx *= Math.Cos(Math.Abs(2 * Math.PI * chromosomeValue));
            }

            functionValueGx = -0.2 * Math.Sqrt(functionValueGx / 5);
            functionValueHx /= chromosomeValue;

            return 20.0 + Math.Exp(1) - 20 * Math.Exp(functionValueGx) - Math.Exp(functionValueHx);
        }
    }
}
